import request from '@/utils/request'

export interface SupplierDTO {
  supplierId?: string
  supplierCode: string
  supplierName: string
  contactPerson?: string
  contactPhone?: string
  contactAddress?: string
  taxNumber?: string
  bankName?: string
  bankAccount?: string
  status?: number
  remark?: string
}

export interface CustomerDTO {
  customerId?: string
  customerCode: string
  customerName: string
  contactPerson?: string
  contactPhone?: string
  contactAddress?: string
  taxNumber?: string
  bankName?: string
  bankAccount?: string
  status?: number
  remark?: string
}

// ========== 供应商接口 ==========

export function pageSupplier(params: { pageNum: number; pageSize: number; code?: string; name?: string; status?: number }) {
  return request({ url: '/erp/party/supplier/page', method: 'get', params })
}

export function getSupplier(id: string) {
  return request({ url: `/erp/party/supplier/${id}`, method: 'get' })
}

export function createSupplier(data: SupplierDTO) {
  return request({ url: '/erp/party/supplier', method: 'post', data })
}

export function updateSupplier(id: string, data: SupplierDTO) {
  return request({ url: `/erp/party/supplier/${String(id)}`, method: 'put', data })
}

export function deleteSupplier(id: string) {
  return request({ url: `/erp/party/supplier/${String(id)}`, method: 'delete' })
}

export function deleteSupplierBatch(ids: string[]) {
  return request({ url: '/erp/party/supplier/batch-delete', method: 'post', data: ids })
}

// ========== 客户接口 ==========

export function pageCustomer(params: { pageNum: number; pageSize: number; code?: string; name?: string; status?: number }) {
  return request({ url: '/erp/party/customer/page', method: 'get', params })
}

export function getCustomer(id: string) {
  return request({ url: `/erp/party/customer/${id}`, method: 'get' })
}

export function createCustomer(data: CustomerDTO) {
  return request({ url: '/erp/party/customer', method: 'post', data })
}

export function updateCustomer(id: string, data: CustomerDTO) {
  return request({ url: `/erp/party/customer/${String(id)}`, method: 'put', data })
}

export function deleteCustomer(id: string) {
  return request({ url: `/erp/party/customer/${String(id)}`, method: 'delete' })
}

export function deleteCustomerBatch(ids: string[]) {
  return request({ url: '/erp/party/customer/batch-delete', method: 'post', data: ids })
}
